package com.googlecode.utterlyidle.multipart;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import static com.googlecode.utterlyidle.multipart.MultipartEntity.multipartEntity;
import static com.googlecode.utterlyidle.multipart.Parts.parts;

public class MultipartEntityBuilder {
    private Boundary boundary;
    private List<Part> parts = new ArrayList<Part>();

    public MultipartEntityBuilder(String boundary) {
        this.boundary = Boundary.boundary(boundary);
    }

    public static MultipartEntityBuilder boundary(final String boundary) {
        return new MultipartEntityBuilder(boundary);
    }

    public MultipartEntityBuilder part(Part part) {
        if(part == null) {
            return this;
        }

        parts.add(part);
        return this;
    }

    public MultipartEntity build() {
        return multipartEntity(boundary, parts(parts, boundary));
    }
}
